
#include "ConfigInfoTester.h"
#include "Sdr.h"
#include "Common_Define.h"
#include "Command_Define.h"
#include "CheckSum.h"
#include "Mmc.h"
#include "Debug.h"


FruInfo m_CfgTesterFruInfo;
void CfgTester_Init(uint8* pBuffer, int nLen, uint8 ipmbAddr, uint8 siteNumber)
{
	static RecordHeader* pRecordArray[10];
	FruInfo_Init(&m_CfgTesterFruInfo, pBuffer, nLen, pRecordArray, 10, Null, Null);
	CfgTester_SetDefault(&m_CfgTesterFruInfo, ipmbAddr, siteNumber);
}

void CfgTester_SetDefault(FruInfo* pFruInfo, uint8 ipmbAddr, uint8 siteNumber)
{
	uint8 len = 0;
	int i = 0;

	#define nHeaderLen  10
	#define FULL_SDR_SIZE  100

	static uint8 g_Temp1SdrDefault[FULL_SDR_SIZE] =
	{
		 FULL_SENSOR_RECORD, 0x00, 0x00 ,0x00, 0x00
		,0x00, 0x31, 0x5A	
		,0x27, 0x00	
		,0xFA	
	};
	static uint8 g_Temp2SdrDefault[FULL_SDR_SIZE] =
	{
		 FULL_SENSOR_RECORD, 0x00, 0x00 ,0x00, 0x00
		,0x00, 0x31, 0x5A	
		,0x27, 0x00	
		,0xFA	
	};
	/*
	static uint8 g_Temp3SdrDefault[FULL_SDR_SIZE] =
	{
		 FULL_SENSOR_RECORD, 0x00, 0x00 ,0x00, 0x00
		,0x00, 0x31, 0x5A	
		,0x27, 0x00	
		,0xFA	
	};
	static uint8 g_Temp4SdrDefault[FULL_SDR_SIZE] =
	{
		 FULL_SENSOR_RECORD, 0x00, 0x00 ,0x00, 0x00
		,0x00, 0x31, 0x5A	
		,0x27, 0x00	
		,0xFA	
	};
	*/
	static uint8 g_V33SdrDefault[FULL_SDR_SIZE] =
	{
		 FULL_SENSOR_RECORD, 0x00, 0x00 ,0x00, 0x00
		,0x00, 0x31, 0x5A	
		,0x27, 0x00	
		,0xFA	
	};
	static uint8 g_V12SdrDefault[FULL_SDR_SIZE] =
	{
		 FULL_SENSOR_RECORD, 0x00, 0x00 ,0x00, 0x00
		,0x00, 0x31, 0x5A	
		,0x27, 0x00	
		,0xFA	
	};
	
	static RecordItem recordLenTable[] =
	{
		    {g_Temp1SdrDefault		, 0}
		  , {g_Temp2SdrDefault		, 0}
		  //, {g_Temp3SdrDefault		, 0}
		  //, {g_Temp4SdrDefault		, 0}
		  , {g_V33SdrDefault		, 0}
		  , {g_V12SdrDefault		, 0}
	};

	FullSensorRecord	g_Temp1FullSensorRecord;
	FullSensorRecord	g_Temp2FullSensorRecord;
	//FullSensorRecord	g_Temp3FullSensorRecord;
	//FullSensorRecord	g_Temp4FullSensorRecord;
	FullSensorRecord	g_V33FullSensorRecord;
	FullSensorRecord	g_V12FullSensorRecord;
	
	static SensorItem g_SensorItem[] =
	{
		 {ET_THRESHOLD, TEMPERATURE1_SENSOR_ID	, TEMPERATURE_SENSOR, 0x0A, 0x80, 0x0A, 0x80, FULL_SENSOR_RECORD, 0, 0, "Temp1"}
		,{ET_THRESHOLD, TEMPERATURE2_SENSOR_ID	, TEMPERATURE_SENSOR, 0x0A, 0x80, 0x0A, 0x80, FULL_SENSOR_RECORD, 0, 0, "Temp2"}
		//,{ET_THRESHOLD, TEMPERATURE3_SENSOR_ID	, TEMPERATURE_SENSOR, 0x0A, 0x80, 0x0A, 0x80, FULL_SENSOR_RECORD, 0, 0, "Temp3"}
		//,{ET_THRESHOLD, TEMPERATURE4_SENSOR_ID	, TEMPERATURE_SENSOR, 0x0A, 0x80, 0x0A, 0x80, FULL_SENSOR_RECORD, 0, 0, "Temp4"}
		,{ET_THRESHOLD, VOLTAGE33_SENSOR_ID		, VOLTAGE_SENSOR	, 0x0A, 0x80, 0x0A, 0x80, FULL_SENSOR_RECORD, 0, 0, "3.3v"}
		,{ET_THRESHOLD, VOLTAGE12_SENSOR_ID		, VOLTAGE_SENSOR	, 0x0A, 0x80, 0x0A, 0x80, FULL_SENSOR_RECORD, 0, 0, "12v"}
	};
	static Threshold g_ThresholdItem[] =
	{
		{80, 75, 70, 0, 0, 0}		// for Temp Sensor
		,{39, 37, 35, 30, 28, 26}		// for 3.3v Sensor
		,{18, 16, 14, 10, 8, 6}		// for 3.3v Sensor
	};
	
	i = 0;
	FullSensorRecord_Init(&g_Temp1FullSensorRecord,TEMPERATURE1_RECORD_ID, &g_SensorItem[i++], &g_ThresholdItem[0], ipmbAddr, siteNumber);
	FullSensorRecord_Init(&g_Temp2FullSensorRecord,TEMPERATURE2_RECORD_ID, &g_SensorItem[i++], &g_ThresholdItem[0], ipmbAddr, siteNumber);
	//FullSensorRecord_Init(&g_Temp3FullSensorRecord,TEMPERATURE3_RECORD_ID, &g_SensorItem[2], &g_ThresholdItem[0], ipmbAddr, siteNumber);
	//FullSensorRecord_Init(&g_Temp4FullSensorRecord,TEMPERATURE4_RECORD_ID, &g_SensorItem[3], &g_ThresholdItem[0], ipmbAddr, siteNumber);
	FullSensorRecord_Init(&g_V33FullSensorRecord	,VOLTAGE3_3_RECORD_ID, &g_SensorItem[i++], &g_ThresholdItem[1], ipmbAddr, siteNumber);
	FullSensorRecord_Init(&g_V12FullSensorRecord	,VOLTAGE12_RECORD_ID , &g_SensorItem[i++], &g_ThresholdItem[2], ipmbAddr, siteNumber);

	i = 0;
	len = g_Temp1FullSensorRecord.m_SdrHeader.m_Len + SDR_HEADER_LEN;
	recordLenTable[i++].m_Len = (uint8)(nHeaderLen + len);
	memcpy(&g_Temp1SdrDefault[nHeaderLen], &g_Temp1FullSensorRecord, len);

	len = g_Temp2FullSensorRecord.m_SdrHeader.m_Len + SDR_HEADER_LEN;
	recordLenTable[i++].m_Len = nHeaderLen + len;
	memcpy(&g_Temp2SdrDefault[nHeaderLen], &g_Temp2FullSensorRecord, len);
	/*
	len = g_Temp3FullSensorRecord.m_SdrHeader.m_Len + SDR_HEADER_LEN;
	recordLenTable[i++].m_Len = nHeaderLen + len;
	memcpy(&g_Temp3SdrDefault[nHeaderLen], &g_Temp3FullSensorRecord, len);
	
	len = g_Temp4FullSensorRecord.m_SdrHeader.m_Len + SDR_HEADER_LEN;
	recordLenTable[i++].m_Len = nHeaderLen + len;
	memcpy(&g_Temp4SdrDefault[nHeaderLen], &g_Temp4FullSensorRecord, len);
	*/
	
	len = g_V33FullSensorRecord.m_SdrHeader.m_Len + SDR_HEADER_LEN;
	recordLenTable[i++].m_Len = nHeaderLen + len;
	memcpy(&g_V33SdrDefault[nHeaderLen], &g_V33FullSensorRecord, len);
	
	len = g_V12FullSensorRecord.m_SdrHeader.m_Len + SDR_HEADER_LEN;
	recordLenTable[i++].m_Len = nHeaderLen + len;
	memcpy(&g_V12SdrDefault[nHeaderLen], &g_V12FullSensorRecord, len);
	
	FruInfo_SetDefault(pFruInfo, recordLenTable, sizeof(recordLenTable) / sizeof(RecordItem));
}

